< previous page page_567 next page >

Page 567
The GetDriveType Function
If youre writing an application that pulls some of its data from a CD-ROM drive, you can ask the user to fill in the drive letter of the CD-ROM or you can potentially retrieve that information yourself using the GetDriveType() function. Of course, if the user has more than one CD-ROM drive, you have to ask which one contains the CD-ROM youre looking for. Alternatively, you could just go look for a certain file on each of the CD-ROM drives until you find the right one.
The GetDriveType() function returns a long value you use to compare against one of five constants to determine the type of the disk drive. Table 28.2 lists the constants and what each one means.
Table 28.2 Drive Type Constants.
ConstantDescription
DRIVE_REMOVABLEThe disk is removable media, such as a floppy disk drive.
DRIVE_FIXEDThe disk is a hard disk on the machine.
DRIVE_NETWORKThe disk is a network or remote drive.
DRIVE_CD_ROMThe disk is a CD-ROM.
DRIVE_UNKNOWNThe disk type cannot be determined or is not present.

Examples Filename: ApiDrive.frm
In the sample form shown in Figure 28.7, a combo box is loaded with the letters A through Z. When you select one of the letters from the combo box, the Click event calls the GetDriveType() function to determine which type of disk drive the letter represents. Heres the code:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cboDrive_Click()
   Dim lngType As Long

   ' Call the GetDriveType function
   ' to Retrieve the drive type
   lngType = GetDriveType(cboDrive.Text & ":\")
   Select Case lngType
      Case DRIVE_REMOVABLE
         txtDriveType = "Drive is Removable Media"

 
< previous page page_567 next page >

If you like this book, buy it!